# -*- coding: utf-8 -*-
# @Author : HaleShi
# @Time : 2023-06-07
# @File : 13_buvid.py

import uuid
import hashlib
import random


# 生成随机的mac地址
def create_random_mac(sep=":"):
    # 00:90:4C:11:22:33
    data_list = []
    for i in range(1, 7):
        part = "".join(random.sample("0123456789ABCDEF", 2))
        data_list.append(part)
    mac = sep.join(data_list)
    return mac


# 对mac地址进行MD5加密，加密后提取2、12、22三个位置数据，转化成大写
def get_buvid_by_wifi_mac():
    mac = create_random_mac()
    md5 = hashlib.md5()
    md5.update(mac.encode('utf-8'))
    print("这是mac地址:", mac)
    v0_1 = md5.hexdigest()  # 转化成16进制表达
    print("这是mac地址进行了16进制转换后的数值：", v0_1)
    # print(v0_1[2], v0_1[12], v0_1[22], v0_1)
    return "XY{}{}{}{}".format(v0_1[2], v0_1[12], v0_1[22], v0_1).upper()


if __name__ == '__main__':
    buvid = get_buvid_by_wifi_mac()
    print(buvid)
